{extend name="public:base" /}

{block name="body"}
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-header layuiadmin-card-header-auto">
	  {if condition="checkRuleButton('admin/forum/addtags')"}
        <button class="layui-btn layuiadmin-btn-tags" data-type="add">添加</button>
		{/if}
      </div>
      <div class="layui-card-body">    
        <table id="LAY-app-content-tags" lay-filter="LAY-app-content-tags"></table>
		<script type="text/html" id="buttonHot">
		{if condition="checkRuleButton('admin/Forum/tagshot')"}<input type="checkbox" name="is_hot" lay-skin="primary" lay-filter="menu-show" {{# if(d.is_hot ==1){ }}checked value="0"{{#  } else { }}value="1"{{#  } }} id="{{d.id}}" >
		{else /}<input type="checkbox" title="禁用" disabled> {/if}
        </script>
        <script type="text/html" id="layuiadmin-app-cont-tagsbar">
		{if condition="checkRuleButton('admin/forum/tagsform')"}
          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
		{else /}<a class="layui-btn layui-btn-disabled layui-btn-normal layui-btn-xs"><i class="layui-icon layui-icon-edit"></i>编辑</a>{/if}
        {if condition="checkRuleButton('admin/forum/tagsdelete')"} 
		  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
		{else /}<a class="layui-btn layui-btn-disabled layui-btn-danger layui-btn-xs"><i class="layui-icon layui-icon-delete"></i>删除</a>{/if}
        </script>
      </div>
    </div>
  </div>

{/block}

{block name="js"}
  <script>
  var forumList = "{:url('Forum/list')}",
      forumListdel = "{:url('Forum/listdel')}",
      forumListform = "{:url('Forum/listform')}",
      forumReplys = "{:url('Forum/replys')}",
      forumRedel = "{:url('Forum/redel')}",
      forumReplysform = "{:url('Forum/replysform')}",
      forumTags = "{:url('Forum/tags')}",
      forumTagsDelete = "{:url('Forum/tagsdelete')}",
      forumTagsForm = "{:url('Forum/tagsform')}";
  layui.config({
    base: '/static/admin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'forum', 'table','form'], function(){

    var table = layui.table,
	form = layui.form;
    var $ = layui.$, active = {
      add: function(){
        layer.open({
          type: 2
          ,title: '添加分类'
          ,content: 'tagsform.html'
          ,area: ['400px', '350px']
          ,btn: ['确定', '取消']
          ,yes: function(index, layero){
            var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags")
            ,sort = othis.find('input[name="sort"]').val()
            ,tags = othis.find('input[name="tags"]').val()
            ,ename = othis.find('input[name="ename"]').val()
            ,desc = othis.find('input[name="desc"]').val();
            
            if(!tags.replace(/\s/g, '')) return;
			
        $.ajax({
				type:"post",
				url:"{:url('admin/Forum/addtags')}",
				data:{"sort":sort,"catename":tags,"ename":ename,"desc":desc},
				daType:"json",
				success:function (data){
					if (data.code == 0) {
						layer.msg(data.msg,{
							icon:6,
							time:2000
						});
					} else {
						layer.open({
							title:'添加失败',
							content:data.msg,
							icon:5,
							anim:6
						});
					}
				}
			});
            table.reload('LAY-app-content-tags');
            layer.close(index);
          }
        }); 
      }
    }

//分类热点控制
	form.on('checkbox(menu-show)', function(data){
	var data = data.elem;
	if(data.checked == true){
			data.value = 1;
		}else{
			data.value = 0;
		}
	$.ajax({
			type:'post',
			url:"{:url('admin/Forum/tagshot')}",
			data:{"id":data.id,"is_hot":data.value,},
			dataType:'json',
			success:function(data){
				if(data.code == 0){
					layer.msg(data.msg,{
						icon:6,
						time:2000
					}
					//,function(){location.reload();}
					);
				} else {
					layer.open({
						title:'修改失败',
						content:data.msg,
						icon:5,
						adim:6
					})
				}
			}
		});
	return false;
	});

	
    $('.layui-btn.layuiadmin-btn-tags').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
  </script>
{/block}
